package com.huawei.cloud.phone.management.domain.connection.status;

import com.huawei.cloud.phone.management.common.BeanFactory;
import com.huawei.cloud.phone.management.domain.connection.ConnectionGateway;
import com.huawei.cloud.phone.management.domain.connection.ConnectionStatus;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class AbstractState implements ConnectionState {

    /**
     * 更新状态
     *
     * @param connectionId 连接ID
     * @param target       目标状态
     */
    protected void updateState(String connectionId, ConnectionStatus target) {
        ConnectionGateway gateway = BeanFactory.getBean(ConnectionGateway.class);
        boolean result = gateway.updateStatus(connectionId, getCurrentStatus(), target);
        if (!result) {
            log.warn("connection {} status has change", connectionId);
        }
    }

    /**
     * 获取当前状态
     *
     * @return 当前状态
     */
    abstract ConnectionStatus getCurrentStatus();
}
